--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx
+ version="1.0"
+ creator="GPSBabel - http://www.gpsbabel.org"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.topografix.com/GPX/1/0"
+ xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
+<time>2012-04-17T08:26:58Z</time>
+<bounds minlat="-36.722941300" minlon="142.175800700" maxlat="-36.716685300" maxlon="142.198467900"/>
+<trk>
+ <name>Track 937</name>
+ <desc>14/04/2012 3:54 pm</desc>
+<trkseg>
+<trkpt lat="-36.720798700" lon="142.177066800">
+ <ele>145.411000</ele>
+ <time>2012-04-14T07:08:11.906Z</time>
+</trkpt>
+<trkpt lat="-36.720713300" lon="142.176767600">
+ <ele>145.683000</ele>
+ <time>2012-04-14T07:08:11.906Z</time>
+</trkpt>
+<trkpt lat="-36.720713300" lon="142.176767600">
+ <ele>145.808000</ele>
+</trkpt>
+<trkpt lat="-36.720796000" lon="142.176806200">
+ <ele>145.736000</ele>
+ <time>2012-04-14T07:09:35.906Z</time>
+</trkpt>
+</trkseg>
+</trk>
+</gpx>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx
+ version="1.0"
+ creator="GPSBabel - http://www.gpsbabel.org"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.topografix.com/GPX/1/0"
+ xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
+<time>1970-01-01T00:00:00Z</time>
+<bounds minlat="-36.720798700" minlon="142.176806200" maxlat="-36.720796000" maxlon="142.177066800"/>
+<trk>
+ <name>Track 937</name>
+ <desc>14/04/2012 3:54 pm</desc>
+<trkseg>
+<trkpt lat="-36.720798700" lon="142.177066800">
+ <ele>145.411000</ele>
+ <time>2012-04-14T07:08:11.906Z</time>
+</trkpt>
+</trkseg>
+<trkseg>
+<trkpt lat="-36.720796000" lon="142.176806200">
+ <ele>145.736000</ele>
+ <time>2012-04-14T07:09:35.906Z</time>
+</trkpt>
+</trkseg>
+</trk>
+</gpx>
--- /dev/null
+#
+# tracks filter merge,discard option tests
+#
+
+rm -f ${TMPDIR}/discard*
+
+# gpx file with points with missing timestamps (has 4 trkpts, 2 duplicate times, 1 missing time, expect merge to output 2 valid trkpts)
+# expecting this to fail during a standard -x track,merge so call directly rather than via gpsbabel function
+${PNAME} -t -i gpx -f ${REFERENCE}/track/trackfilter_discard.gpx -x track,merge -o csv -F - && {
+ echo "$PNAME succeeded! (it shouldn't have with this input...)"
+}
+# ... but should get through if we discard the points.
+gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter_discard.gpx -x track,merge,discard -o gpx -F ${TMPDIR}/discard.gpx
+compare ${REFERENCE}/track/trackfilter_discard_out.gpx ${TMPDIR}/discard.gpx
(based on patch from Vladimir Kondratiev)
2007-07-26: Allow 'range' together with trackpoints without timestamp
2010-06-02: Add specified timestamp to each trackpoint (added by sven_luzar)
+ 2012-05-04: Added 'discard' option to 'merge' to throw out track points without timestamp
*/
#include <ctype.h>
#define TRACKFILTER_TRK2SEG_OPTION "trk2seg"
#define TRACKFILTER_SEGMENT_OPTION "segment"
#define TRACKFILTER_FAKETIME_OPTION "faketime"
+#define TRACKFILTER_DISCARD_OPTION "discard"
#undef TRACKF_DBG
static char *opt_trk2seg = NULL;
static char *opt_segment = NULL;
static char *opt_faketime = NULL;
+static char *opt_discard = NULL;
static
arglist_t trackfilter_args[] = {
"Add specified timestamp to each trackpoint",
NULL, ARGTYPE_STRING, ARG_NOMINMAX
},
+ {
+ TRACKFILTER_DISCARD_OPTION, &opt_discard,
+ "Discard track points without timestamps during merge",
+ NULL, ARGTYPE_BOOL, ARG_NOMINMAX
+ },
ARG_TERMINATOR
};
static trkflt_t *track_list = NULL;
static int track_ct = 0;
static int track_pts = 0;
+static int timeless_pts = 0;
static int opt_interval = 0;
static int opt_distance = 0;
static char need_time; /* initialized within trackfilter_init */
track_pts++;
wpt = (waypoint *)elem;
- if ((need_time != 0) && (wpt->creation_time == 0)) {
+ if(wpt->creation_time == 0) timeless_pts++;
+ if (!(opt_merge && opt_discard) && (need_time != 0) && (wpt->creation_time == 0)) {
fatal(MYNAME "-init: Found track point at %f,%f without time!\n",
wpt->latitude, wpt->longitude);
}
waypoint *prev, *wpt;
route_head *master = track_list[0].track;
- if (track_pts < 1) {
+ if (track_pts-timeless_pts < 1) {
return;
}
- buff = (waypoint **)xcalloc(track_pts, sizeof(*buff));
+ buff = (waypoint **)xcalloc(track_pts-timeless_pts, sizeof(*buff));
j = 0;
for (i = 0; i < track_ct; i++) { /* put all points into temp buffer */
route_head *track = track_list[i].track;
QUEUE_FOR_EACH((queue *)&track->waypoint_list, elem, tmp) {
wpt = (waypoint *)elem;
- buff[j++] = waypt_dupe(wpt);
+ if(wpt->creation_time != 0) {
+ buff[j++] = waypt_dupe(wpt);
+ }
track_del_wpt(track, wpt);
waypt_free(wpt);
}
}
track_ct = 1;
- qsort(buff, track_pts, sizeof(*buff), trackfilter_merge_qsort_cb);
+ qsort(buff, track_pts-timeless_pts, sizeof(*buff), trackfilter_merge_qsort_cb);
- dropped = 0;
+ dropped = timeless_pts;
prev = NULL;
- for (i = 0; i < track_pts; i++) {
+ for (i = 0; i < track_pts-timeless_pts; i++) {
wpt = buff[i];
if ((prev == NULL) || (prev->creation_time != wpt->creation_time)) {
route_add_wpt(master, wpt);